using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Kaskelot.SP.Core;
using Kaskelot.SP.Services;
using Microsoft.SharePoint;

namespace Kaskelot.SP.UI.Features.BemanningPages
{
	/// <summary>
	/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
	/// </summary>
	/// <remarks>
	/// The GUID attached to this class may be used during packaging and should not be modified.
	/// </remarks>

	[Guid("5ff91a9b-4a01-4689-accb-18189e395f1d")]
	public class BemanningPagesEventReceiver : SPFeatureReceiver
	{
		// Uncomment the method below to handle the event raised after a feature has been activated.

		public override void FeatureActivated(SPFeatureReceiverProperties properties)
		{
			Logger.LogVerbose(this, LayerNames.UI, "BemanningPagesEventReceiver.FeatureActivated", "Entered");

			SPWeb web = properties.Feature.Parent as SPWeb;

			using (PageService svc = new PageService(web))
			{
				// Ensure page
				svc.CreatePage(Constants.Bemanning.Pages.StartPage, "Bemanning", Constants.PageLayouts.DetailsPage);
				// Ensure webparts
				svc.DeleteAllWebParts(Constants.Bemanning.Pages.StartPage);

				WebParts.BemanningValdistriktSearch.BemanningValdistriktSearch wp2 = new WebParts.BemanningValdistriktSearch.BemanningValdistriktSearch();
				svc.AddWebPart(Constants.Bemanning.Pages.StartPage, wp2, Constants.WebPartZones.Tab1, 0);

				WebParts.BemanningGrupperSearch.BemanningGrupperSearch wp3 = new WebParts.BemanningGrupperSearch.BemanningGrupperSearch();
				svc.AddWebPart(Constants.Bemanning.Pages.StartPage, wp3, Constants.WebPartZones.Tab2, 0);

				WebParts.BemanningVakanserSearch.BemanningVakanserSearch wp = new WebParts.BemanningVakanserSearch.BemanningVakanserSearch();
				svc.AddWebPart(Constants.Bemanning.Pages.StartPage, wp, Constants.WebPartZones.Tab3, 0);

				WebParts.BemanningInkomnaAnsokningar.BemanningInkomnaAnsokningar wp8 = new WebParts.BemanningInkomnaAnsokningar.BemanningInkomnaAnsokningar();
				svc.AddWebPart(Constants.Bemanning.Pages.StartPage, wp8, Constants.WebPartZones.Tab4, 0);

				WebParts.BemanningInkomnaAnmalan.BemanningInkomnaAnmalan wp9 = new WebParts.BemanningInkomnaAnmalan.BemanningInkomnaAnmalan();
				svc.AddWebPart(Constants.Bemanning.Pages.StartPage, wp9, Constants.WebPartZones.Tab5, 0);

				svc.CreatePage(Constants.Bemanning.Pages.ValdistriktDetailsPage, "Bemanning", Constants.PageLayouts.DetailsPage);
				svc.DeleteAllWebParts(Constants.Bemanning.Pages.ValdistriktDetailsPage);

				WebParts.BemanningValdistriktDetails.BemanningValdistriktDetails wp4 = new WebParts.BemanningValdistriktDetails.BemanningValdistriktDetails();
				svc.AddWebPart(Constants.Bemanning.Pages.ValdistriktDetailsPage, wp4, Constants.WebPartZones.Tab1, 0);

				svc.CreatePage(Constants.Bemanning.Pages.GruppDetailsPage, "Bemanning", Constants.PageLayouts.DetailsPage);
				svc.DeleteAllWebParts(Constants.Bemanning.Pages.GruppDetailsPage);

				WebParts.BemanningGrupperDetails.BemanningGrupperDetails wp5 = new WebParts.BemanningGrupperDetails.BemanningGrupperDetails();
				svc.AddWebPart(Constants.Bemanning.Pages.GruppDetailsPage, wp5, Constants.WebPartZones.Tab1, 0);

				// Ensure page
				svc.CreatePage(Constants.Bemanning.Pages.BlankettPage, "Bemanning", Constants.PageLayouts.StartPage);
				svc.DeleteAllWebParts(Constants.Bemanning.Pages.BlankettPage);

				// Ensure webparts
				WebParts.BlankettPostDetails.BlankettPostDetails wp7 = new WebParts.BlankettPostDetails.BlankettPostDetails();
				svc.AddWebPart(Constants.Bemanning.Pages.BlankettPage, wp7, Constants.WebPartZones.Top, 0);
			}

			Logger.LogVerbose(this, LayerNames.UI, "BemanningPagesEventReceiver.FeatureActivated", "Exiting");
		}


		// Uncomment the method below to handle the event raised before a feature is deactivated.

		//public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
		//{
		//}


		// Uncomment the method below to handle the event raised after a feature has been installed.

		//public override void FeatureInstalled(SPFeatureReceiverProperties properties)
		//{
		//}


		// Uncomment the method below to handle the event raised before a feature is uninstalled.

		//public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
		//{
		//}

		// Uncomment the method below to handle the event raised when a feature is upgrading.

		//public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
		//{
		//}
	}
}
